const axios = require('axios');
const MockAdapter = require('axios-mock-adapter');
const normalAxios = axios.create();
const mockAxios = axios.create();
import _config from "./config";
import reqTools from "../utils/reqTools";

// 广告机发布广告
var mock = new MockAdapter(mockAxios);

mock.onGet('/advRelease/getAll').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.get('/api/advScreenInfo',config.params).then(res => {
      resolve([200, res.data]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});


mock.onDelete('/advRelease/delete').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.delete('/api/advScreenInfo/'+config.id).then((res) => {
      resolve([200, res]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});
//添加我发布的广告
mock.onPost('/advRelease/add').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.post( '/api/advScreenInfo/my_public',config.data
    ).then((res) => {
      resolve([200, res]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});
//添加我申请的广告
mock.onPost('/advOutRelease/add').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.post( '/api/advScreenInfo/my_askfor',config.data
    ).then((res) => {
      resolve([200, res]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});
//审核申请的广告
mock.onPost('/advScreenInfo/exam/add').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.post( '/api/advScreenInfo/my_exam',config.data
    ).then((res) => {
      resolve([200, res]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});
//添加系统广告
mock.onPost('/system/advRelease/add').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.post( '/api/advScreenInfo/system_public',config.data
    ).then((res) => {
      resolve([200, res]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});
mock.onPut('/advRelease/update').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.put( '/api/advScreenInfo', config.data, 
   ).then((res) => {
      resolve([200, res ]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});
//付款
mock.onGet('/adv/advScreenInfo/pay').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.get('/api/advScreenInfo/pay',config.params).then(res => {
      resolve([200, res]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});
//查询钱包余额
mock.onGet('/office/queryWallet').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.get('/api/sysOffice/queryWallet',config.params).then(res => {
      resolve([200, res]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});
mock.onGet('/adv/getAdvById').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.get('/api/advScreenInfo/'+config.id).then(res => {
      resolve([200, res.data]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});
//消耗日志
mock.onGet('/pageLog/getAll').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.get('/api/advScreenInfo/findPageLog',config.params).then(res => {
      resolve([200, res.data]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});

export default mockAxios;
